package net.huashitong.scheduling.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.huashitong.Indicators.databean.CompletionClassificationDatabean;
import net.huashitong.Indicators.entity.CompletionClassification;
import net.huashitong.Indicators.filter.CompletionClassificationFilter;
import net.huashitong.scheduling.service.PreemptiveService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.utils.ObjectUtils;
/**
 * 争先进位
 * @author lzr
 *
 */
@Controller
@RequestMapping("/app/preemptive")
public class PreemptiveController extends JsonBaseController {

	@Autowired
	private PreemptiveService preemptiveService;
	public static final String[] years={"2022", "2021", "2020","2019","2018","2017","2016"};
	@Override
	protected String getView(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * 查找扶贫县数据
	 */
	@ResponseBody
	@RequestMapping("/queryCountyPreemptive")
	public Message queryCountyPreemptive(@RequestBody CompletionClassificationFilter filter){
		 Map<String, Object> map = new HashMap<String, Object>();
		List<CompletionClassification> classifications= new ArrayList<CompletionClassification>();
		 if(ObjectUtils.isBlank(filter.getYear())){
			 for(int j=0;j<PreemptiveController.years.length;j++){
				 filter.setYear(years[j]);
				 classifications = preemptiveService.queryCountyPreemptive(filter);
				 if(ObjectUtils.isNotBlank(classifications)){
					 break;
				 }
			 }
		 
		 }else{
			 classifications = preemptiveService.queryCountyPreemptive(filter);
		 }
		List<CompletionClassificationDatabean> classificationDatabeans = new ArrayList<CompletionClassificationDatabean>();
		if(ObjectUtils.isNotBlank(classifications)){
		for (CompletionClassification completionClassification : classifications) {
			CompletionClassificationDatabean classificationDatabean = new CompletionClassificationDatabean();
			classificationDatabean.setActualCompletionValue(completionClassification.getActualCompletionValue());
			classificationDatabean.setUnit("亿元");
			classificationDatabean.setArea(completionClassification.getArea());
			classificationDatabeans.add(classificationDatabean);
		}
	   } 
		map.put("lists",classificationDatabeans);
		map.put("date", filter.getYear());
 		return coverMessage("200", "数据获取成功", map);
	}
	/**
	 * 前六末六数据
	 */
	@ResponseBody
	@RequestMapping("/queryPreemptive")
	public Message queryPreemptive(@RequestBody CompletionClassificationFilter filter){
		filter.setCategory("争先进位");
		List<CompletionClassificationDatabean> classificationDatabeans = preemptiveService.queryPreemptive(filter);
 		return coverMessage("200", "数据获取成功", classificationDatabeans);
	}
	
}
